// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TemplatesSettingsManager.cs" company="Roman '4ux-nbIx' Novitsky">
//   Copyright (c) Roman '4ux-nbIx' Novitsky 2009
// </copyright>
// <summary>
//   Describes and manipulates the templates settings manager.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace SettingsManager.ComponentSettingsManagers
{
  #region Namespace Imports

  using System.Xml;

  using JetBrains.ComponentModel;

  #endregion


  /// <summary>
  /// Describes and manipulates the templates settings manager.
  /// </summary>
  internal sealed class TemplatesSettingsManager : ResharperComponentSettingsManager
  {
    #region Constructors and Destructors

    /// <summary>
    /// Initializes a new instance of the <see cref="TemplatesSettingsManager"/> class.
    /// </summary>
    public TemplatesSettingsManager()
      : base("SharedSolutionTemplateManager", "Shared Templates")
    {
    }

    #endregion


    #region Public Methods

    /// <summary>
    /// Loads the settings.
    /// </summary>
    /// <param name="component">The component.</param>
    /// <param name="element">The element.</param>
    /// <param name="options">The options.</param>
    public override void LoadSettings(IXmlExternalizableComponent component, XmlElement element, object options)
    {
      var type = component.GetType();

      try
      {
        var beforeSolutionOpenedMethodInfo = type.GetMethod("BeforeSolutionClosed");
        beforeSolutionOpenedMethodInfo.Invoke(component, null);
      }
      catch
      {
        return;
      }

      base.LoadSettings(component, element, options);

      try
      {
        var afterSolutionOpenedMethodInfo = type.GetMethod("AfterSolutionOpened");
        afterSolutionOpenedMethodInfo.Invoke(component, null);
      }
      catch
      {
        return;
      }
    }


    #endregion
  }
}